package com.sky.blog.vo;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

/**
 * @author sky  2022/3/23
 * @version 1.0
 */

@Data
public class PageResult<T> {

    @ApiModelProperty(example = "1563", value = "总记录数")
    private Long total;

    @ApiModelProperty(example = "1", value = "当前页码")
    private Long current;

    @ApiModelProperty(example = "10", value = "当前页返回记录数")
    private Long size;

    @ApiModelProperty(example = "~", value = "详细内容列表")
    private List<T> records;

    public PageResult() {
    }

    /**
     * 将mybatis-plus的分页Bean转化成自己的分页Bean
     *
     * @param page 查询的分页返回集
     */
    public PageResult(IPage<T> page) {
        // 记录详情
        this.records = page.getRecords();
        this.total = page.getTotal();
        this.current = page.getCurrent();
        this.size = page.getPages();
    }

    /**
     * 将mybatis-plus的分页Bean转化成自己的分页Bean
     *
     * @param page    查询的分页返回集
     * @param records 自定义返回的数据
     */
    public PageResult(IPage<?> page, List<T> records) {
        this.records = records;
        this.total = page.getTotal();
        this.current = page.getCurrent();
        this.size = page.getSize();
    }
}
